package com.ljkj.cordial.chat.ui.views;

import com.lanjiu.lib.imclient.bus.EventConstants;
import com.lanjiu.lib.imclient.bus.MessageEvent;
import com.lanjiu.lib.imclient.dto.VersionDto;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.ljkj.cordial.chat.ui.IView;

/**
 * @description:
 * @author: Panwei
 * @date: 2020/1/4 15:23
 */
public class VersionInfoView extends IView {

    private VersionInfoCallback mCallback;

    public VersionInfoView(VersionInfoCallback mCallback) {
        this.mCallback = mCallback;
    }

    public void doCheckUpdate() {
        doSendRequest(EventConstants.Action.CHECK_FOR_UPDATES, new VersionDto().toJson());
    }

    @Override
    protected void onMessageEventHandle(MessageEvent event) {
        if (event.action() == EventConstants.Action.CHECK_FOR_UPDATES) {
            VersionDto version = null;
            if (checkIsSuccess(event.code(), event.data()))
                version = Dto.fromJson(event.data(), VersionDto.class);
            if (mCallback != null)
                mCallback.onCheckVersionCallback(event.code(), event.msg(), version);
        }
    }

    public interface VersionInfoCallback {
        void onCheckVersionCallback(int code, String msg, VersionDto data);
    }
}
